﻿

using Microsoft.EntityFrameworkCore;
using PlatformUW.Contracts;

namespace PlatformUW.EntityFramework.Repositories
{
    public abstract class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        protected PlatformDBContext respositoryContext { get; set; }

        protected BaseRepository(PlatformDBContext repositoryContext)
        {
            this.respositoryContext = repositoryContext;                
        }
        
        public Task AddAsync(T entity)
        {
           return Task.FromResult(respositoryContext.Set<T>().Add(entity));
        }

        public Task DeleteAsync(T entity)
        {
            return Task.FromResult(respositoryContext.Set<T>().Remove(entity));
        }

        public async Task<IEnumerable<T>> FindAsync(Func<T, bool> predicate)
        {
            return await Task.FromResult(respositoryContext.Set<T>().Where(predicate).AsEnumerable());
        }

        public Task<IEnumerable<T>> GetAllAsync()
        {
            return Task.FromResult(respositoryContext.Set<T>().AsEnumerable());
        }

        public Task UpdateAsync(T entity)
        {
            return Task.FromResult(respositoryContext.Set<T>().Update(entity));
        }
    }
}
